from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-16 14:02:31.002410
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 16, Aug, 2022
Time: 14:02:36
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1449
Nobs: 750.000 HQIC: -50.4856
Log likelihood: 9524.39 FPE: 9.58497e-23
AIC: -50.6993 Det(Omega_mle): 8.50785e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.292489 0.055289 5.290 0.000
L1.Burgenland 0.109072 0.036700 2.972 0.003
L1.Kärnten -0.107198 0.019459 -5.509 0.000
L1.Niederösterreich 0.205857 0.076519 2.690 0.007
L1.Oberösterreich 0.110078 0.074794 1.472 0.141
L1.Salzburg 0.254091 0.039217 6.479 0.000
L1.Steiermark 0.041426 0.051172 0.810 0.418
L1.Tirol 0.108632 0.041529 2.616 0.009
L1.Vorarlberg -0.062232 0.035621 -1.747 0.081
L1.Wien 0.052371 0.066130 0.792 0.428
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060708 0.115308 0.526 0.599
L1.Burgenland -0.033737 0.076540 -0.441 0.659
L1.Kärnten 0.047284 0.040583 1.165 0.244
L1.Niederösterreich -0.175405 0.159585 -1.099 0.272
L1.Oberösterreich 0.407291 0.155986 2.611 0.009
L1.Salzburg 0.287310 0.081790 3.513 0.000
L1.Steiermark 0.108121 0.106721 1.013 0.311
L1.Tirol 0.311750 0.086611 3.599 0.000
L1.Vorarlberg 0.024772 0.074290 0.333 0.739
L1.Wien -0.030425 0.137919 -0.221 0.825
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187721 0.028372 6.616 0.000
L1.Burgenland 0.090022 0.018833 4.780 0.000
L1.Kärnten -0.008839 0.009986 -0.885 0.376
L1.Niederösterreich 0.259386 0.039267 6.606 0.000
L1.Oberösterreich 0.138450 0.038381 3.607 0.000
L1.Salzburg 0.044956 0.020125 2.234 0.025
L1.Steiermark 0.020771 0.026259 0.791 0.429
L1.Tirol 0.093346 0.021311 4.380 0.000
L1.Vorarlberg 0.056683 0.018279 3.101 0.002
L1.Wien 0.118616 0.033936 3.495 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107349 0.028809 3.726 0.000
L1.Burgenland 0.045593 0.019123 2.384 0.017
L1.Kärnten -0.013828 0.010139 -1.364 0.173
L1.Niederösterreich 0.189185 0.039871 4.745 0.000
L1.Oberösterreich 0.301608 0.038972 7.739 0.000
L1.Salzburg 0.109683 0.020435 5.367 0.000
L1.Steiermark 0.103301 0.026664 3.874 0.000
L1.Tirol 0.105774 0.021639 4.888 0.000
L1.Vorarlberg 0.069286 0.018561 3.733 0.000
L1.Wien -0.018814 0.034458 -0.546 0.585
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125328 0.052471 2.389 0.017
L1.Burgenland -0.049608 0.034829 -1.424 0.154
L1.Kärnten -0.041036 0.018467 -2.222 0.026
L1.Niederösterreich 0.171085 0.072619 2.356 0.018
L1.Oberösterreich 0.138557 0.070981 1.952 0.051
L1.Salzburg 0.288670 0.037219 7.756 0.000
L1.Steiermark 0.036217 0.048564 0.746 0.456
L1.Tirol 0.164045 0.039412 4.162 0.000
L1.Vorarlberg 0.099245 0.033806 2.936 0.003
L1.Wien 0.069415 0.062760 1.106 0.269
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055108 0.041774 1.319 0.187
L1.Burgenland 0.040110 0.027729 1.447 0.148
L1.Kärnten 0.050729 0.014703 3.450 0.001
L1.Niederösterreich 0.217222 0.057815 3.757 0.000
L1.Oberösterreich 0.294751 0.056511 5.216 0.000
L1.Salzburg 0.043406 0.029631 1.465 0.143
L1.Steiermark 0.000660 0.038663 0.017 0.986
L1.Tirol 0.144598 0.031378 4.608 0.000
L1.Vorarlberg 0.071514 0.026914 2.657 0.008
L1.Wien 0.082591 0.049966 1.653 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172345 0.049919 3.452 0.001
L1.Burgenland -0.001716 0.033136 -0.052 0.959
L1.Kärnten -0.062980 0.017569 -3.585 0.000
L1.Niederösterreich -0.079682 0.069087 -1.153 0.249
L1.Oberösterreich 0.189091 0.067529 2.800 0.005
L1.Salzburg 0.057795 0.035409 1.632 0.103
L1.Steiermark 0.236060 0.046202 5.109 0.000
L1.Tirol 0.499512 0.037495 13.322 0.000
L1.Vorarlberg 0.044281 0.032162 1.377 0.169
L1.Wien -0.052556 0.059708 -0.880 0.379
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161474 0.057586 2.804 0.005
L1.Burgenland -0.009398 0.038225 -0.246 0.806
L1.Kärnten 0.066757 0.020268 3.294 0.001
L1.Niederösterreich 0.207508 0.079698 2.604 0.009
L1.Oberösterreich -0.069909 0.077901 -0.897 0.369
L1.Salzburg 0.210865 0.040847 5.162 0.000
L1.Steiermark 0.119679 0.053298 2.245 0.025
L1.Tirol 0.072380 0.043254 1.673 0.094
L1.Vorarlberg 0.119671 0.037101 3.226 0.001
L1.Wien 0.122458 0.068878 1.778 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357904 0.033049 10.829 0.000
L1.Burgenland 0.007422 0.021938 0.338 0.735
L1.Kärnten -0.023663 0.011632 -2.034 0.042
L1.Niederösterreich 0.212820 0.045740 4.653 0.000
L1.Oberösterreich 0.199445 0.044709 4.461 0.000
L1.Salzburg 0.044096 0.023443 1.881 0.060
L1.Steiermark -0.013315 0.030588 -0.435 0.663
L1.Tirol 0.104823 0.024824 4.223 0.000
L1.Vorarlberg 0.071397 0.021293 3.353 0.001
L1.Wien 0.040883 0.039530 1.034 0.301
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039033 0.141700 0.192876 0.152843 0.121240 0.106005 0.063313 0.219021
Kärnten 0.039033 1.000000 -0.006921 0.131959 0.039435 0.093998 0.432227 -0.053742 0.097206
Niederösterreich 0.141700 -0.006921 1.000000 0.334379 0.142686 0.294456 0.098999 0.178967 0.314324
Oberösterreich 0.192876 0.131959 0.334379 1.000000 0.228466 0.326038 0.176389 0.167264 0.261959
Salzburg 0.152843 0.039435 0.142686 0.228466 1.000000 0.145101 0.114906 0.144462 0.125040
Steiermark 0.121240 0.093998 0.294456 0.326038 0.145101 1.000000 0.149980 0.136184 0.073576
Tirol 0.106005 0.432227 0.098999 0.176389 0.114906 0.149980 1.000000 0.110870 0.145009
Vorarlberg 0.063313 -0.053742 0.178967 0.167264 0.144462 0.136184 0.110870 1.000000 0.001491
Wien 0.219021 0.097206 0.314324 0.261959 0.125040 0.073576 0.145009 0.001491 1.000000